using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using BUS;
using DAL;
using Entities;
using Utility;

public partial class KhachHang_Hienthiloaisanpham : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadData();
        }

    }
    private void LoadData()
    {

        int id = int.Parse(Request.QueryString["loai"].ToString());

        Pager.PageSize = 5;
        Criteria c = new Criteria();
        int total = 0;
        c.add(Condition.AND, tbSanPham.tbSanPhamColumns.IDLoaiSP .ToString(), Condition.EQUAL, int.Parse(id.ToString()));
        // c.add(Condition.AND, tbSanPham.tbSanPhamColumns.IDL.ToString(), Condition.EQUAL, int.Parse(Request.QueryString ["id"]));
        tbSanPham.tbSanPhamCollection dd_Collection = tbSanPhamBus.Get(c.Criter, Pager.CurrentIndex, Pager.PageSize,
        tbSanPham.tbSanPhamColumns.IDSanPham  .ToString(), OrderDirection.ASC.ToString(), out total);
        Repeater2.DataSource = dd_Collection;
        Repeater2.DataBind();
        Pager.ItemCount = total;
        if (total <= Pager.PageSize)
            Pager.Visible = false;
    }
    protected void Pager_Command(object sender, CommandEventArgs e)
    {
        Pager.CurrentIndex = int.Parse(e.CommandArgument.ToString());
        LoadData();
    }
    protected void Repeater2_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.AlternatingItem ||
            e.Item.ItemType == ListItemType.Item)
        {
            tbSanPham sp = (tbSanPham)e.Item.DataItem;
            HyperLink hyp_sp = (HyperLink)e.Item.FindControl("hyp_sp");
            Literal lit_idsp = (Literal)e.Item.FindControl("lit_idsp");
            Image img_hinhanh = (Image)e.Item.FindControl("img_hinhanh");
            Literal lit_mota = (Literal)e.Item.FindControl("lit_mota");
            Label lb_tk = (Label)e.Item.FindControl("lb_tk");
            hyp_sp.Text = sp.TenSanPham;
           
            // tinh tiet kiem 
            float tk = ((sp.GiaTriThuc - sp.GiaBan) / (float)sp.GiaTriThuc * 100);
            lb_tk.Text = Math.Round(tk) + "%";


            if (sp.MoTaSP.Length > 60)
            {
                lit_mota.Text = sp.MoTaSP.Substring(0, 60) + "...";

            }
            else
            {
                lit_mota.Text = sp.MoTaSP;
            }


            int IDH = tbHinhAnhBus.imageFirt(int.Parse(sp.IDSanPham.ToString()));
            tbHinhAnh hh = tbHinhAnhBus.GetByID(IDH);

            img_hinhanh.ImageUrl = "~/Admin/Photos/Thumb/" + hh.TenHinh.ToString();
            //hyp_sp.NavigateUrl = "SanPhamCT.aspx?id= " + sp.IDSP.ToString();        
            HyperLink btct = (HyperLink)e.Item.FindControl("btct");
            //btct.NavigateUrl = "CTSanPham.aspx?id= " + sp.IDSanPham .ToString();
        }

    }

   
}
